package com.linchuansi.fetureTask;

import java.util.concurrent.*;

/**
 * test*
 *
 * @author wb
 * @date 2025-11-22 21:46*@since 1.0.0
 */
public class FutureTaskDemo {
    static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(5));
    public static void main(String[] args) throws InterruptedException {
        FutureTask futureTask=new FutureTask(()->{
            System.out.println("开始执行");
            Thread.sleep(1000);
            return "hello world";
        });
        threadPoolExecutor.submit(futureTask);
        try {
            try {
                System.out.println(futureTask.get(100, TimeUnit.MILLISECONDS));
            } catch (TimeoutException e) {
                //e.printStackTrace();
                System.out.println("超时");
            }
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
